package sax;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

public class ReaderXML
{
	public static void main(String[] args)
	{
		try
		{
			XMLReader xmlReader = XMLReaderFactory.createXMLReader();

			FileReader reader = new FileReader("persone.xml");
			InputSource inputSource = new InputSource(reader);

			xmlReader.setContentHandler(new PersonHandler());

			xmlReader.parse(inputSource);

			ContentHandler tuttiCA = xmlReader.getContentHandler();
			ArrayList<Person> tutt = ((PersonHandler) tuttiCA).getTutti();
			for (Person p : tutt)
				System.out.println(p);

		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		catch (SAXException e)
		{
			e.printStackTrace();
		}
	}
}
